<template>
	<view class="main box_redius">
		<view class="service flex flex_align" v-for="item in addressList" :key="item.id" @click="confirmSelect(item)">
			<image class="mar_right" src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/index10.png" mode=""></image>
			<view class="firm_city">
				<view class="company">{{item.name}}</view>
				<view class="phone"><text>联系电话：</text>{{item.phone}}</view>
				<view>{{item.addr}}</view>
			</view>
			<view class="copy">
				<text @click="copy(item)">复制</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		addressList
	} from '@/api/address.js'
	export default {
		data() {
			return {
				addressList: [],
				selectAddress: ''
			}
		},
		onLoad(options) {
			if (options.selectAddress) {
				this.selectAddress = options.selectAddress
			}
		},
		onShow() {
			this.getaddressList()
		},
		methods: {
			//选择售后点
			confirmSelect(item) {
				let that = this
				if (this.selectAddress === 'confirm') {
					uni.navigateBack({
						delta: 1,
						success: function() {
							that.$store.commit('editAddressId', item)
							uni.setStorageSync('user_address_id', item.id)
							that.$store.commit('editFirmAddress', item)
						}
					});
				}
			},
			//售后地址列表
			getaddressList() {
				addressList({}).then(res => {
					this.addressList = res.data
					this.$store.commit('editAddressId', res.data[0])
					uni.setStorageSync('user_address_id', res.data[0].id)
				}).catch(err => {}).catch(err => {
					this.addressList = []
				})
			},
			//复制
			copy(item) {
				let that = this
				uni.setClipboardData({
					data: `${item.addr},${item.name},${item.phone}`,
					success(res) {
						that.$u.toast('复制成功')
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.service {
		padding: 20rpx 0;

		+.service {
			margin: 0px;
			border-top: 1rpx solid rgb(214, 215, 217);
			width: 100%;
			border-top-color: rgb(214, 215, 217);
			border-right-color: rgb(214, 215, 217);
			border-left-color: rgb(214, 215, 217);
		}

		image {
			width: 34rpx;
			height: 40rpx;
		}

		.firm_city {
			line-height: 40rpx;
			flex: 1;

			.company {
				color: #333333;
				line-height: 20px;
			}
		}
	}

	.copy {
		width: 20%;
		text-align: center;

		text {
			border: 1px solid rgb(230, 230, 230);
			padding: 5px 10px;
			letter-spacing: 2px;
		}
	}
</style>
